package com.zy.rpc.common.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @author zy
 * @date 2023/7/19 17:44
 */

@Data
@AllArgsConstructor
public class ApiResponse implements Serializable {
    private Integer status;
    private Boolean success;
    private String errorMsg;
    private Object data;
    private Long total;

    public ApiResponse() {

    }

    public static ApiResponse ok() {
        return new ApiResponse(200, true, null, null, null);
    }

    public static ApiResponse ok(Object data) {
        return new ApiResponse(200, true, null, data, null);
    }

    public static ApiResponse ok(List<?> data, Long total) {
        return new ApiResponse(200, true, null, data, total);
    }

    public static ApiResponse fail(String errorMsg) {
        return new ApiResponse(400, false, errorMsg, null, null);
    }

    @Override
    public String toString() {
        return "操作结果{" +
                "返回状态=" + status +
                ", 是否成功=" + success +
                '}';
    }
}
